<%@page import="com.is.export.control.SelectOptionValue"%>
<%@page import="java.util.LinkedHashMap"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="com.is.control.AttendanceDetailControl"%>
<%@page import="com.is.control.ParamClassControl"%>
<%@page import="com.is.model.ParamStuyear"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<%@page import="com.is.control.CourseClassControl"%>
<%@page import="com.is.model.CourseClass"%>
<%@page import="java.util.List"%>
<%@page import="com.is.control.StudentControl"%>
<%@page import="com.is.model.Student"%>
<%@page import="com.is.util.ParamUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.is.util.DesData"%>
<%@page import="com.is.control.ParamCourseControl"%>
<%@page import="com.is.export.model.AttendanceExport"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.is.control.ParamReasonTypeGSControl"%>
<%@page import="com.is.control.AttendanceTimeControl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../../resources/css/user_info.css" />
<style type="text/css">
	#caption{height:30px; line-height:30px; text-align:left;padding-top:10px;}
	table thead tr th{background:#7BC671;}
</style>
<title>个人出勤情况</title>
</head>
<body>
 <div id="add_info">
 <%
         // 单个学生所有课程出席情况
         DesData des = new DesData();
         String stu=ParamUtil.getString(request,"stuId");
         int stuId = Integer.parseInt(des.decrypt(stu));
         Student cs = StudentControl.getStudent(stuId);
         int classId = Integer.parseInt(cs.getClassId());
         int stuyear = ParamUtil.getInt(request,"stuyear",ParamStuyearControl.getCurrentStuyearId());
         List<CourseClass> ccs = CourseClassControl.getAllCourseClassIdByClassIdAndStuyear(classId,stuyear);
         List<AttendanceExport> exportList = new ArrayList<AttendanceExport>(); //导出的list
 %>

 <form action="allCoursesOneStu.jsp" method="post">
 <table>
 <caption id="caption">请选择</caption>
 <tr>
 	<td style="height: 36px;">
 		<select name="stuyear">
		 <%
		         List<ParamStuyear> years = ParamStuyearControl.getAllStuyear();
		         for(ParamStuyear ps:years){
		 %>
		 <option value="<%=ps.getId() %>" <%if(ps.getId()==stuyear)out.print("selected"); %>><%=ps.getStuyear() %></option>
		 <%} %>
		 </select>
 	</td>
 	<td>
 		 <input type="hidden" value="<%=stu %>" name="stuId" />
		 <input type="submit" value="查询" />&nbsp;&nbsp;
		 <input type="button" value="导出结果"  onclick="window.location.href='/InterStu/servlet/ExportDo'" />
 	</td>
 </tr>
 </table>
 </form>
 <form>
 <table>
  <caption id="caption"> <%=cs.getChineseName() %>的出勤情况</caption>
 <thead>
 	 <tr>
		 <th>课程</th>
		 <th>迟到</th>
		 <th>缺勤</th>
		 <th>病假</th>
		 <th>事假</th>
		 <th>合计点名次数</th>
		 <th>折为总缺勤数</th>
		 <th>缺勤率</th>
	 </tr>
 </thead>
<tbody>
 <%
         for(CourseClass cc:ccs){
             %>
             <tr>
             <td><%=ParamCourseControl.getCourseById(cc.getCourseId()).getCourseName() %></td>
             <%
             int countTimes = AttendanceTimeControl.getCount(cc.getId(),stuyear,"","");
			  float totalQQ=0;
             int totalDM = AttendanceTimeControl.getCount(cc.getId(),stuyear,"","");
			  boolean flag = true;
		          int count2 = AttendanceDetailControl.getCount(2,cs.getId(),cc.getId()+"",stuyear,"","");
		          int num2 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(2,stuyear);
		          if(num2==0){
		        	  flag = false;
		          }else{
		        	  totalQQ+= (float)count2/num2;
		          }
		          int count3 = AttendanceDetailControl.getCount(3,cs.getId(),cc.getId()+"",stuyear,"","");
		          int num3 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(3,stuyear);
		          if(num3==0){
		        	  flag = false;
		          }else{
		        	  totalQQ+= (float)count3/num3;
		          }
		          int count4 = AttendanceDetailControl.getCount(4,cs.getId(),cc.getId()+"",stuyear,"","");
		          int num4 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(4,stuyear);
		          if(num4==0){
		        	  flag = false;
		          }else{
		        	  totalQQ+= (float)count4/num4;
		          }
		          int count5 =AttendanceDetailControl.getCount(5,cs.getId(),cc.getId()+"",stuyear,"","");
		          int num5 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(5,stuyear);
		          if(num5==0){
		        	  flag = false;
		          }else{
		        	  totalQQ+= (float)count5/num5;
		          }
		          float absenceRate = 0;
		          String absencePer="";
		          if(countTimes == 0){
		          	  //flag = false;
		          	   absenceRate = 0;
		          	   absencePer = "0";
		          } else{
		        	  NumberFormat nt = NumberFormat.getPercentInstance();
		        	  nt.setMinimumFractionDigits(2);
		          	  absenceRate = totalQQ/countTimes;
		          	  absencePer =nt.format(absenceRate);
		          }
		          exportList.add(new AttendanceExport(cs.getChineseName(),ParamCourseControl.getCourseById(cc.getCourseId()).getCourseName(),count2+"",count3+"",count4+"",count5+"",totalDM+"",totalQQ+"",absencePer));
				      %>
				  <td><%=flag?count2:"公式有错误或者尚未设置，请联系管理员"%></td>
				  <td><%=flag?count3:"公式有错误或者尚未设置，请联系管理员"%></td>
				  <td><%=flag?count4:"公式有错误或者尚未设置，请联系管理员"%></td>
				  <td><%=flag?count5:"公式有错误或者尚未设置，请联系管理员"%></td>
				  <td><%=totalDM %></td>
				  <td><%=flag?totalQQ:"公式有错误或者尚未设置，请联系管理员"%></td>
				  <td><%=flag?absencePer:"公式有错误或者尚未设置，请联系管理员"%></td>
		        		  <%
		        		  }
	
	session.removeAttribute("exportList");
	session.setAttribute("exportList",exportList);
	session.removeAttribute("fileName");
	session.setAttribute("fileName",cs.getChineseName()+ParamStuyearControl.getStuyear(stuyear).getStuyear()+"出勤情况");
	LinkedHashMap<String,String> exportOps = SelectOptionValue.AttendanceOptions();
	session.removeAttribute("exportOps");
	 session.setAttribute("exportOps",exportOps);
	 session.removeAttribute("className");
	 session.setAttribute("className","com.is.export.model.AttendanceExport");
	        		  %>
 </tbody>
 </table>
 </form>
 <br/>
 </div>
</body>
</html>